package com.xiaoxx.coin.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@AllArgsConstructor
@NoArgsConstructor
public enum PositionSideEnum {
    BOTH("BOTH", "单一持仓方向"),
    LONG("LONG", "多头（双向持仓下）"),
    SHORT("SHORT", "空头（双向持仓下）");
    @EnumValue
    private String code;  // 枚举值
    private String description;  // 枚举描述

    public static PositionSideEnum fromCode(String code) {
        for (PositionSideEnum side : PositionSideEnum.values()) {
            if (side.getCode().equals(code)) {
                return side;
            }
        }
        throw new IllegalArgumentException("Unexpected code: " + code);
    }
}
